<?php
//页面显示
class PurviewAction extends BaseAction {
	var $dao;
	
	function _initialize(){
		$this->checkAdmin();
		$this->dao  = D( 'Purview' );
	}
	
	function index(){
		$channel = D('Channel', 'portal')->findall();
		$this->assign('channel', $channel);	
		
		if(!empty($_GET['channelId'])){
			$map['channelId'] = intval($_GET['channelId']);
		}
		$map['categoryId'] = array('exp','IS NULL');
		
		$order = $this->_getOrder();
		
		$list = $this->dao->where($map)->order($order)->findpage();
		foreach ($list['data'] as &$v){
			$purview = unserialize( $v['purview'] );
			$v = array_merge($v, $purview);
		}
		$this->assign('list', $list);
		
		$this->display();
	}	
	
	function doAdd(){
		$user = $_POST['user'];
		if(empty($user)){
			$this->error('管理员ID/域账号不能为空');
		}

		if(is_numeric($user)){
			$map['uid'] = $user;
		}else{
			$map['uname'] = $user;
		}
		$u = M('User')->where( $map )->field('uid')->find();
		$uid = $u['uid'];

		if(!$uid){
			$this->error('指定用户不存在');
		}
		
		$res = $this->dao->addPurview($uid);
		if($res){
			$user = getUserName($uid);
			D('Log','admin')->addLog($this->mid, array('user'=>$user), 'portal_admin_add');
		}
		$this->echoRes($res, '增加管理员');
	}
	
	function doEidt(){
		$res = $this->dao->eidtPurview();
		$this->echoRes($res, '保存');		
	}
	
	function doDel(){
		$id = intval($_GET['id']);
		if(empty($id)){
			$this->error('参数出错');
		}
		
		$res = $this->dao->where("id='$id'")->delete();
		if($res){
			D('Log','admin')->addLog($this->mid, '', 'portal_admin_del');
		}		
		$this->echoRes($res, '删除管理员');
	}
}
?>